package com.yc.sakuralxm.uestcscanning.pop

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.PopupWindow
import android.widget.TextView

import com.yc.sakuralxm.uestcscanning.R


/**
 * Created by sakuraLxm on 2016/12/28.
 */
class InPop(private val context: Context, private val listener: DisconnectPopDismissListener) {
    private var viewRankPopupView: ViewGroup? = null
    private var popupWindow: PopupWindow? = null

    interface DisconnectPopDismissListener {
        fun dismissDo(s: String)
    }

    fun init(): PopupWindow {
        if (viewRankPopupView == null) {
            val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
            viewRankPopupView = inflater.inflate(R.layout.pop_in, null) as ViewGroup


            val disconnectListener = DisconnectListener()

        }
        if (popupWindow == null) {
            popupWindow = PopupWindow(viewRankPopupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
            popupWindow!!.isFocusable = true
            popupWindow!!.isOutsideTouchable = true
            popupWindow!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
            popupWindow!!.animationStyle = R.style.style_pop
        }
        return popupWindow as PopupWindow
    }


    private inner class DisconnectListener : View.OnClickListener {
        override fun onClick(view: View) {
            when (view.id) {

            }//                case R.id.idDialogFragmentSure:
        }
    }

    fun show(view: View, dismissListener: PopupWindow.OnDismissListener) {
        init().showAtLocation(view, Gravity.CENTER, 0, 0)
        popupWindow!!.setOnDismissListener(dismissListener)
    }
}
